package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.mapper.MenuMapper;
import com.itheima.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service(interfaceClass = MenuService.class)
public class MenuServiceImpl implements MenuService {
    @Autowired
    private MenuMapper menuMapper;


    @Override
    public List<Map> getAllMenu(String username) {

        List<Map>list= menuMapper.getAllMenu(username);
        for (Map map : list) {
       int id=(int) map.get("id");
      List<Map>mapList= menuMapper.getSecondMenu();
            ArrayList <Map> list1=new ArrayList <>();
            for (Map map1 : mapList) {
               int parentMenuId=(int) map1.get("parentMenuId");
               if (id==parentMenuId){
                   list1.add(map1);

               }
            }
            map.put("children",list1);


        }

        return list;
    }
}
